package mq.rabbitmq.direct;

import com.rabbitmq.client.Channel;
import mq.rabbitmq.RabbitMqChannelFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static mq.rabbitmq.Constant.DIRECT_EX_CHANGE;
import static mq.rabbitmq.Constant.DIRECT_ROUTING_KEY;


/**
 * 生产者
 *
 * @author verlet
 * @date 2019/9/11
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 声明channel
        Channel channel = RabbitMqChannelFactory.createChannel();
        // 发布消息
        channel.basicPublish(DIRECT_EX_CHANGE, DIRECT_ROUTING_KEY, null, (DIRECT_EX_CHANGE + "==》Hello RabbitMQ!").getBytes());
        System.out.println("发布一条消息成功。");
        // 关闭连接
        RabbitMqChannelFactory.close(channel);
    }
}
